package GameTools;

public class ydMath {

	
	public static ydPoint slopeOf(ydPoint p1, ydPoint p2) {
		return new ydPoint((p2.x - p1.x), (p2.y - p1.y));
	}
	
	public static double hypotenuse(ydPoint p1, ydPoint p2) {
		return Math.hypot(p1.x - p2.x, p1.y - p2.y);
	}
	
	public static float radsToDegrees(float rads){
		return (float) (rads * 180 / Math.PI);
	}
	
	public static float degreesToRads(float degree){
		return (float) (degree / 180 * Math.PI);
	}
	
	public static float vectorToDegrees(ydPoint slope) {

		ydPoint slopeVector=new ydPoint(slope);
		
		if (slopeVector.y == 0)
			if (slopeVector.x > 0)
				return 0;
			else
				return 180;

		if (slopeVector.x == 0)
			if (slopeVector.y > 0)
				return 90;
			else
				return 270;

		float extra = 0;

		if (slopeVector.x >= 0 && slopeVector.y > 0) {
			extra = 0;
			slopeVector.y *= 1;
		} else if (slopeVector.x < 0 && slopeVector.y >= 0) {
			float tmp = slopeVector.y;
			slopeVector.x *= -1;
			slopeVector.y = slopeVector.x;
			slopeVector.x = tmp;
			extra = 90;
		} else if (slopeVector.x <= 0 && slopeVector.y < 0) {
			float tmp = slopeVector.y;
			slopeVector.x *= 1;
			// slopeVector.y=slopeVector.x;
			// slopeVector.x=tmp;
			extra = 180;
		} else if (slopeVector.x > 0 && slopeVector.y < 0) {
			float tmp = slopeVector.y;
			slopeVector.x *= 1;
			slopeVector.y = slopeVector.x;
			slopeVector.x = -tmp;
			extra = 270;
		}

		return Globals.radsToDegrees((float) Math.atan(slopeVector.y
				/ slopeVector.x))
				+ extra;
	}
	
	public static float vectorToRads(ydPoint slopeVector) {
		return ydMath.degreesToRads(ydMath.vectorToDegrees(slopeVector));
	}
	
	public static double cosineLaw(ydPoint A, ydPoint B,ydPoint C){
		
		double lenthA=ydMath.hypotenuse(A, C);
		double lenthB=ydMath.hypotenuse(A, B);
		double lenthC=ydMath.hypotenuse(B, C);
		
		return Math.acos((Math.pow(lenthA, 2) -  Math.pow(lenthB, 2)-Math.pow(lenthC,2))
				/ (-2 * lenthB * lenthC));
	}
	
}
